package study.java.jdk.jdk8._7_optional;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.Optional;

@Slf4j
public class Optional2Test {

    @Test
    public void orElse_test() {
        Car car = new Car("audi", "red");
        Car def = new Car("bmw", "black");
        Car myCar = Optional.ofNullable(car)
                .orElse(def);
        log.info("{}", myCar);
    }

    @Test
    public void orElseGet_test() {
        Car car = new Car("audi", "red");
        Car def = new Car("bmw", "black");
        Car myCar = Optional.ofNullable(car).orElseGet(() -> new Car());
        log.info("{}", myCar);
    }

    @Test
    public void orElseThrow_test() {
        Car car = new Car("audi", "red");
        Car def = new Car("bmw", "black");
        Car myCar = Optional.ofNullable(car).orElseThrow(() -> new RuntimeException("safasd"));
        log.info("{}", myCar);
    }
}
